package com.icinfo.cloud.provider.common.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ObjectUtils;

/**
 * 描述：redisson配置类
 *
 * @Author zhengqiang
 * @Date 2022/10/17 21:05
 **/
@Configuration
public class RedissonConfig {
    @Value("${spring.cf_redis.host}")
    private String redisHost;

    @Value("${spring.zf_redis.port}")
    private int redisPort;

    @Value("${spring.cf_redis.password}")
    private String password;


    /**
     * 创建redisson客户端
     * @return
     */
    @Bean
    public RedissonClient getRedisson(){
        Config config = new Config();
        //单机模式
        System.out.println(redisHost + ":" + redisPort);
        if (ObjectUtils.isEmpty(password)) {
            password = null;
        }
        config.useSingleServer()
                .setAddress("redis://" + redisHost + ":" + redisPort)
                .setPassword(password);
        return Redisson.create(config);
    }

}
